// miniprogram/pages/plan/plan.js
let Runcount=0,keepcount=0,deepcount=0,plancount=0
let day=0
let isnow=true
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isRun:true,
    iskeep:true,
    isdeep:true,
    isplan:true,
    Runcount:0,
    keepcount:0,
    deepcount:0,
    plancount:0,
    createday:new Date().getDate(),
    getday:0
  },
click(e){
  console.log(day);
  let that =this
  if (day!=that.data.createday) {
    isnow=false
    that.setData({
      isRun:true,
      iskeep:true,
      isdeep:true,
      isplan:true
    })
  }
  
  if (that.data.isRun||that.data.iskeep||that.data.isplan||this.data.isdeep) {
console.log(e.currentTarget.dataset.x);
console.log(that.data.isRun);
if(that.data.isRun){
if(e.currentTarget.dataset.x==1){
  Runcount++;
  that.setData({
    Runcount:Runcount,
    isRun:false
  })
}
}
if(that.data.iskeep){
 if(e.currentTarget.dataset.x==2){
  keepcount++;
  that.setData({
    keepcount:keepcount,
    iskeep:false
  })
 }
}
if(that.data.isdeep){
 if(e.currentTarget.dataset.x==3){
  deepcount++;
  that.setData({
    deepcount:deepcount,
    isdeep:false
  })
}
}
if(that.data.isplan){
if(e.currentTarget.dataset.x==4){
  plancount++;
  that.setData({
    plancount:plancount,
    isplan:false
  })
}
}
var senconds =23*3600+59*60+59
console.log(senconds);
console.log(that.data.Runcount);
wx.cloud.callFunction({
  name:'addkeep',
  data:{
    createday:that.data.createday,
    Runcount:that.data.Runcount,
    keepcount:that.data.keepcount,
    deepcount:that.data.deepcount,
    plancount:that.data.plancount,
    isRun:that.data.isRun,
    isdeep:that.data.isdeep,
    iskeep:that.data.iskeep,
    isplan:that.data.isplan
  },
  success(res){
    console.log(res);
  }
})
  }
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:   function (options) {
    let that =this
     wx.cloud.callFunction({
      name:'getkeep',
      data:{},
      success(res){
        console.log(res);
        day=res.result.data[res.result.data.length-1].createday

        that.setData({
          isRun:res.result.data[res.result.data.length-1].isRun,
          isdeep:res.result.data[res.result.data.length-1].isdeep,
          iskeep:res.result.data[res.result.data.length-1].iskeep,
          isplan:res.result.data[res.result.data.length-1].isplan,
          Runcount:res.result.data[res.result.data.length-1].Runcount,
          keepcount:res.result.data[res.result.data.length-1].keepcount,
          deepcount:res.result.data[res.result.data.length-1].deepcount,
          plancount:res.result.data[res.result.data.length-1].plancount
        })
        Runcount=res.result.data[res.result.data.length-1].Runcount;
        keepcount=res.result.data[res.result.data.length-1].keepcount;
        deepcount=res.result.data[res.result.data.length-1].deepcount;
        plancount=res.result.data[res.result.data.length-1].plancount
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
